package com.youlu.campus.admin.organizer;

import com.youlu.campus.admin.utils.AuthUtils;
import com.youlu.campus.common.base.RestResult;
import com.youlu.campus.common.base.RestResultBuilder;
import com.youlu.campus.entity.ActivityOrganizerInfo;
import com.youlu.campus.entity.VO.req.ActivityOrganizeBatchVerify;
import com.youlu.campus.entity.VO.req.ActivityOrganizerQueryVO;
import com.youlu.campus.service.organizer.ActivityOrganizerInfoService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
public class ActivityOrganizerInfoController {
    @Autowired
    private ActivityOrganizerInfoService activityOrganizerInfoService;

    @PostMapping("/organizer/page")
    public QResult orderPage(@RequestBody ActivityOrganizerQueryVO req) {
        req.setBizFrom("admin");
        req.setUserId(AuthUtils.getUserId());
        return QResult.success(activityOrganizerInfoService.list(req));
    }

    @GetMapping("/organizer/find-one")
    public QResult findOne(@RequestParam("id") String id) {
        return QResult.success(activityOrganizerInfoService.findOne(id));
    }

    @PostMapping("/organizer/update")
    public QResult orderPage(@RequestBody ActivityOrganizerInfo req) {
        return QResult.success(activityOrganizerInfoService.update(req));
    }

    @PostMapping("/organizer/batch/verify")
    public QResult batchVerify(@RequestBody ActivityOrganizeBatchVerify req) {
        return QResult.success(activityOrganizerInfoService.batchVerify(req));
    }

    /**
     * 承办单位信息导出
     *
     * @param
     * @param
     */
    @PostMapping("/organizer/export")
    public RestResult orderExport(@RequestParam("activityId") String activityId) {
        boolean result = activityOrganizerInfoService.export(activityId, null, AuthUtils.getLoginName(), AuthUtils.getUserId());
        log.info(":>>> 导出订单结果:{}", result);
        if (result) {
            return RestResultBuilder.builder().success().build();
        }
        return RestResultBuilder.builder().failure().build();
    }
}
